home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / lib / parsarpwho.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-18  |  3.9 KB  |  140 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: parsarpwho.c,v 5.3 1993/01/19 05:07:05 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.3 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: parsarpwho.c,v $
  17.  * Revision 5.3  1993/01/19  05:07:05  syd
  18.  * Trim erroreous extra log entry
  19.  * From: Syd
  20.  *
  21.  * Revision 5.2  1993/01/19  04:47:12  syd
  22.  * Significant changes to provide consistent Date and From_ header
  23.  * cracking.  Overhauled date utilities and moved into library.  Moved
  24.  * real_from() into library.  Modified frm, newmail, and readmsg utilities
  25.  * to use library version of real_from().  Moved get_word() from Elm
  26.  * source into library.  Added new library routines atonum() and strfcpy().
  27.  * Fixed trailing backslash bug in len_next().
  28.  * From: chip@chinacat.unicom.com (Chip Rosenthal)
  29.  *
  30.  * Revision 5.1  1992/10/03  22:41:36  syd
  31.  * Initial checkin as of 2.4 Release at PL0
  32.  *
  33.  *
  34.  ******************************************************************************/
  35.  
  36. /** 
  37.  
  38. **/
  39.  
  40. #include "headers.h"
  41.  
  42. parse_arpa_who(buffer, newfrom, is_really_a_to)
  43. char *buffer, *newfrom;
  44. int is_really_a_to;
  45. {
  46.     /** try to parse the 'From:' line given... It can be in one of
  47.         two formats:
  48.         From: Dave Taylor <hplabs!dat>
  49.         or  From: hplabs!dat (Dave Taylor)
  50.  
  51.         Added: removes quotes if name is quoted (12/12)
  52.         Added: only copies STRING characters...
  53.         Added: if no comment part, copy address instead! 
  54.         Added: if is_really_a_to, this is really a 'to' line
  55.            and treat as if we allow embedded addresses
  56.     **/
  57.  
  58.     int use_embedded_addresses;
  59.     char temp_buffer[LONG_STRING], *temp;
  60.     register int i, j = 0, in_parens;
  61.  
  62.     temp = (char *) temp_buffer;
  63.     temp[0] = '\0';
  64.  
  65.     no_ret(buffer);        /* blow away '\n' char! */
  66.  
  67.     if (lastch(buffer) == '>') {
  68.       for (i=strlen("From: "); buffer[i] != '\0' && buffer[i] != '<' &&
  69.            buffer[i] != '('; i++)
  70.         temp[j++] = buffer[i];
  71.       temp[j] = '\0';
  72.     }
  73.     else if (lastch(buffer) == ')') {
  74.       in_parens = 1;
  75.       for (i=strlen(buffer)-2; buffer[i] != '\0' && buffer[i] != '<'; i--) {
  76.         switch(buffer[i]) {
  77.         case ')':    in_parens++;
  78.             break;
  79.         case '(':    in_parens--;
  80.             break;
  81.         }
  82.         if(!in_parens) break;
  83.         temp[j++] = buffer[i];
  84.       }
  85.       temp[j] = '\0';
  86.       reverse(temp);
  87.     }
  88.  
  89. #ifdef USE_EMBEDDED_ADDRESSES
  90.     use_embedded_addresses = TRUE;
  91. #else
  92.     use_embedded_addresses = FALSE;
  93. #endif
  94.  
  95.     if(use_embedded_addresses || is_really_a_to) {
  96.       /** if we have a null string at this point, we must just have a 
  97.           From: line that contains an address only.  At this point we
  98.           can have one of a few possibilities...
  99.  
  100.           From: address
  101.           From: <address>
  102.           From: address ()
  103.       **/
  104.         
  105.       if (strlen(temp) == 0) {
  106.         if (lastch(buffer) != '>') {       
  107.           for (i=strlen("From:");buffer[i] != '\0' && buffer[i] != '('; i++)
  108.         temp[j++] = buffer[i];
  109.           temp[j] = '\0';
  110.         }
  111.         else {    /* get outta '<>' pair, please! */
  112.           for (i=strlen(buffer)-2;buffer[i] != '<' && buffer[i] != ':';i--)
  113.         temp[j++] = buffer[i];
  114.           temp[j] = '\0';
  115.           reverse(temp);
  116.         }
  117.       }
  118.     }
  119.       
  120.     if (strlen(temp) > 0) {        /* mess with buffer... */
  121.  
  122.       /* remove leading spaces and quotes... */
  123.  
  124.       while (whitespace(temp[0]) || temp[0] == '"')
  125.         temp = (char *) (temp + 1);        /* increment address! */
  126.  
  127.       /* remove trailing spaces and quotes... */
  128.  
  129.       i = strlen(temp) - 1;
  130.  
  131.       while (i >= 0 && (whitespace(temp[i]) || temp[i] == '"'))
  132.        temp[i--] = '\0';
  133.  
  134.       /* if anything is left, let's change 'from' value! */
  135.  
  136.       if (strlen(temp) > 0)
  137.         strfcpy(newfrom, temp, STRING);
  138.     }
  139. }
  140.